package app;
import java.io.IOException;
import java.util.*;

public class Main {
	
	static int k = 0;
	static boolean ponderateFlag = false;
	static String[] attributeValues;
	
	public static void main(String[] args){	
		DataSet dataSet = DataSetReader.read("cheat.cds");
		AttributeSet attributeSet = dataSet.getAttributeSet();
		Vector<Instance> instances = dataSet.getInstanceSet();
		
//		consoleValues(attributeSet);
		predefinedValues();
		
		Instance newInstance = new Instance(attributeSet);
		newInstance.populateWithoutUpdate(attributeValues);
		
		dataSet.kNearestNeighbour(instances, newInstance, k, ponderateFlag);
	}
	
	static void predefinedValues() {
		String strValues = "no,married,80,??";
		
		attributeValues = strValues.split(",");
		k = 3;
		ponderateFlag = true;
	}
	
	static void consoleValues(AttributeSet attributeSet) {
		Scanner input = new Scanner(System.in);
		
		try {
			System.out.println("Introduceti valorile pentru noua instanta");
			System.out.println("(separate prin virgula, fara valoarea clasei):");
			String strValues = input.nextLine();
			
			// add a fake class value
			strValues += ",??";
			
			attributeValues = strValues.split(",");
			if(attributeValues.length != attributeSet.size()) 
				throw new IOException("Numarul de valori nu coincide cu numarul de atribute!");
			
			System.out.print("Introduceti k (numarul celor mai apropiati vecini): ");
			k = input.nextInt();
			
			System.out.println("Folositi ponderare?: (da/nu)");
			if(input.nextLine().equalsIgnoreCase("nu")) {
				ponderateFlag = false;
			} else if(input.nextLine().equalsIgnoreCase("da")) {
					ponderateFlag = true;
				}
			
			input.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}